package com.lanou.controller;


import com.github.pagehelper.PageInfo;
import com.lanou.bean.UserComments;
import com.lanou.service.CompanyService;
import com.lanou.utils.AjaxResult;
import com.lanou.utils.StrUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by dllo on 18/3/12.
 */
@Controller
public class CompanyController {

    @Resource
    private CompanyService companyService;

    /**
     * 郭中宏
     * @param city 城市名
     * @param pageNum 当前页数
     * @param pageSize 每页显示多少条数据
     * @return 返回该城市所有的公司
     * 该接口实现 输入城市名、当前页数、每页显示多少条数据  返回 对应页数的所有城市和当前页数 总页数
     */
    @ResponseBody
    @RequestMapping(value = "/cityCompany")
    private AjaxResult cityCompany(@RequestParam(value = "city") String city, @RequestParam(value = "pageNum",required = false) Integer pageNum,@RequestParam(value = "PageSize",required = false)Integer pageSize){

        city=StrUtils.charSetStr(city);
        return new AjaxResult("200","1.0",companyService.cityCompany(city,pageNum,pageSize));
    }


    /**
     * 郭中宏
     * @param city 城市名
     * @param area 服务区域名
     * @param type 装修类型
     * @param price 承接价格
     * @param pageNum 当前页数
     * @param pageSize 每页显示多少数据
     * @param address 注册区域
     * @param style  专长风格
     * @return 返回对应的公司信息集合
     */
    @ResponseBody
    @RequestMapping(value = "/areaTypePriceCompany")
    private AjaxResult areaTypePriceCompany(@RequestParam(value = "city") String city,
                                            @RequestParam(value = "area",required = false) String area,
                                            @RequestParam(value = "type",required = false) String type,
                                            @RequestParam(value = "price",required = false) String price,
                                            @RequestParam(value = "pageNum",required = false) Integer pageNum,
                                            @RequestParam(value = "pageSize",required = false) Integer pageSize,
                                            @RequestParam(value = "address",required = false) String address,
                                            @RequestParam(value = "style",required = false) String style,
                                            @RequestParam(value = "sort",required = false)String sort){

        city= StrUtils.charSetStr(city);

        area=StrUtils.charSetStr(area);

        type=StrUtils.charSetStr(type);

        price=StrUtils.charSetStr(price);

        address=StrUtils.charSetStr(address);

        style=StrUtils.charSetStr(style);

        sort=StrUtils.charSetStr(sort);
        return new AjaxResult("200","1.0",companyService.areaTypePriceCompany(city,area,type,price,address,style,pageNum,pageSize,sort));
    }

    /**
     * @param company_id   公司id
     * @param state        阶段状态
     * @param commentLevel 被评等级
     * @param pageNum      当前页数
     * @param pageSize     每页的评论数
     * @return 对该公司的所有评论信息
     * 开发人:赵帅
     */
    @ResponseBody
    @RequestMapping("/getAllComment")
    public AjaxResult getAllComments(@RequestParam("company_id") Integer company_id, @RequestParam(value = "state", required = false) String state, @RequestParam(value = "commentLevel", required = false) String commentLevel
            , @RequestParam(value = "pageNum", required = false) Integer pageNum, @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        PageInfo<UserComments> pageInfo = companyService.getAllComments(company_id, state, commentLevel, pageNum, pageSize);
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode("200");
        ajaxResult.setMsg("获取公司的所有评论信息");
        ajaxResult.setData(pageInfo);
        return ajaxResult;
    }

    /**
     *
     * @param company_id 公司id
     * @return 平均评分
     * 开发人赵帅
     */
    @ResponseBody
    @RequestMapping("/AVGScore")
    public AjaxResult getAVGScore(@RequestParam("company_id") Integer company_id) {
        return companyService.getAVGScore(company_id);
    }
    /**
     * zfy
     * 通过公司id cid 获得该公司下所有的订单信息
     * 用于公司首页 免费量房板块的显示
     * @param cid
     * @return
     */
    @ResponseBody
    @RequestMapping("/getcompanyallorder")
    public AjaxResult getCompanyAllOrder(Integer cid){
        return companyService.getAllOrderInfoByCid(cid);
    }


}
